﻿
<cfscript>
    Badge = CreateObject("component", "Badges");
    Badge.init("\\SCFUserShare\Home\bfrick\BadgePhotos");    
</cfscript>

<cfquery name="getBadges" datasource="RosettaStone" cachedwithin="#CreateTimeSpan(0,0,30,0)#">
<!---SELECT     
    r.RosettaID, r.UserAccount, biw.BadgeNumber, biw.PhotoFileName, biw.NumberOfCardsIssued, biw.WhenIssued, biw.CardType,
    iv.IDX, iv.PHOTO, iv.LAST_NAME, iv.FIRST_NAME, iv.ID_CARD_NUM
FROM 
    Rosetta.dbo.RosettaStone AS r INNER JOIN
    Badge_IDWorks.dbo.Badges AS biw ON r.RosettaID = biw.RosettaID INNER JOIN
    IVISPLUS.dbo.IVIS_DATA AS iv ON r.IVIS_IDX = iv.IDX
WHERE     
    (biw.PhotoFileName IS NULL)
ORDER BY 
    r.RosettaID--->
    
SELECT 
    BadgeNum, i.ID_CARD_NUM, R.RosettaID, i.PHOTO, i.LAST_NAME, i.FIRST_NAME, i.IDX, biw.PhotoFileName
FROM 
    SCFVM18.WFCSuite.dbo.BadgeAssign B INNER JOIN 
    SCFDB01.[Rosetta].dbo.[RosettaStone] R ON B.PersonID = R.WFC_PersonID INNER JOIN
    SCFDB01.Badge_IDWorks.dbo.Badges biw ON biw.RosettaID = R.RosettaID Inner Join
    SCFDB01.[IVISPLUS].dbo.[IVIS_DATA] i ON B.BadgeNum = i.ID_CARD_NUM  
WHERE 
    r.Disabled = 0 AND
    expirationdtm > getdate() AND
    i.PHOTO IS NOT NULL AND 
    biw.PhotoFileName IS NULL
ORDER BY 
    i.LAST_NAME
</cfquery>

<cfset ivsPath = '\\scfappshare\ITS_Data\applications\ivisplus\photos' />
<Cfset badgeWorksPath = "\\scfappshare\ITS_Data\IDCentre\BadgePhotos" />

<cfset oldbadgepath = '\\SCFUserShare\Home\bfrick\badge' />
<cfset newbadgepath = '\\SCFUserShare\Home\bfrick\test' />
    
<cfset photoarray = ArrayNew(2)>
                    
<cfloop query="getBadges">
    <cfset photoarray[CurrentRow][1] = PHOTO>
    <cfset photoarray[CurrentRow][2] = RosettaID>
    <cfset photoarray[CurrentRow][3] = BadgeNum>
    <cfset photoarray[CurrentRow][4] = ID_CARD_NUM>
    <cfset photoarray[CurrentRow][5] = FIRST_NAME>
    <cfset photoarray[CurrentRow][6] = LAST_NAME>
<!---    
    <cfset photoarray[CurrentRow][1] = PhotoFileName>
    <cfset photoarray[CurrentRow][2] = RosettaID>
    <cfset photoarray[CurrentRow][3] = BadgeNumber>
    <cfset photoarray[CurrentRow][4] = ID_CARD_NUM>
    <cfset photoarray[CurrentRow][5] = UserAccount>
    <cfset photoarray[CurrentRow][6] = FIRST_NAME>
    <cfset photoarray[CurrentRow][7] = LAST_NAME>
    <cfset photoarray[CurrentRow][8] = photo>--->
</cfloop>

<cfoutput>#getBadges.RecordCount#</cfoutput>

<table width="100%" border='1'>
<tr>
    <td>PhotoFile NOT IN DATABASE</td>
    <td>RosettaID</td>
    <td>BadgeNumber</td>
    <td>ID_CARD_NUM</td>
    <td>Employee</td>
</tr>

<cfset oldbadgepath = '\\SCFUserShare\Home\bfrick\badge' />
<cfset newbadgepath = '\\SCFUserShare\Home\bfrick\test' />

<cfloop from="1" to="#getBadges.RecordCount#" index="x" >
<cftry>
    <cfoutput>
        <cfset folder = Right(photoarray[x][1],Len(photoarray[x][1])-1)>
        <cfset folder = Left(folder, Len(folder)-3)/500>
        <cfset picfolder = Int(folder)+1>
        <cfset pcBadge = 'pic#picfolder#\#photoarray[x][1]#' />
        <cfset newPic = Replace("#badgeWorksPath#\#photoarray[x][6]#_#photoarray[x][5]#_#photoarray[x][2]#.jpg",',', '_', "All") />
        <!---<cffile action="readBinary" file="#oldbadgepath#\#pcBadge#" variable = "CopyOfPic"  />
        <cfset newPic = Replace("#newbadgepath#\#photoarray[x][6]#_#photoarray[x][5]#_#photoarray[x][2]#.jpg",',', '_', "All") />
        <cfset newPicThumb = Replace("#newbadgepath#\thumbs\#photoarray[x][6]#_#photoarray[x][5]#_#photoarray[x][2]#.jpg",',', '_', "All") />       
        <cfimage action="resize" width="30%" height="30%" source="#CopyOfPic#" name="thumb" /><!---        
        <cfimage action="write" source="#CopyOfPic#" destination="#newPic#" overwrite="no"/>--->
        <cfimage action="write" source="#thumb#" destination="#newPicThumb#" overwrite="no"/>--->
        
        <!---
        <Cfset badgePic = '\\scfappshare\ITS_Data\IDCentre\BadgePhotos\' & photoarray[x][7] & '_' & photoarray[x][6] & '_' & photoarray[x][2] & '.jpg' />
        <cfset badgePic = Replace(badgePic,',', '_', "All") />
        --->
        <tr>
            <td>&nbsp;#newPic# </td>
            <td>&nbsp;#photoarray[x][2]#</td>
            <td>&nbsp;#photoarray[x][3]#</td>
            <td>&nbsp;#photoarray[x][4]#</td>
            <td>&nbsp;#photoarray[x][5]# #photoarray[x][6]#</td>
        </tr>
        
        <!---<cfquery name="FirstLook" datasource="RosettaStone">
            UPDATE 
                Badge_IDWorks.dbo.Badges
            SET
                PhotoFileName = '#newPic#',
                BadgeNumber = #val(photoarray[x][4])#
            WHERE
                RosettaID = #photoarray[x][2]#
        </cfquery>--->

    </cfoutput>
<cfcatch type="Any" >
    
</cfcatch>
</cftry>

</cfloop>

</table>